
if exists (select 1 from sysobjects where name = 'vw_arbeitsplanactive' and type = 'V')
begin
   drop view vw_arbeitsplanactive
   print 'View: vw_arbeitsplanactive deleted ...'
end
go
create view vw_arbeitsplanactive
as

   select planid = ap.PlanID, 
          atid = ap.ATID, 
          planname = ap.Name, 
          jahrid = ap.JahrID, 
          schemaid = ap.SchemaID, 
          von = ap.Von, 
          bis = ap.Bis,
          schemaname = s.Name
     from ArbeitsPlan ap
    inner join Schemas s
       on s.SchemaID = ap.SchemaID 
    where ap.Status = 1 

go
print 'View: vw_arbeitsplanactive done ...'
go

grant select on vw_arbeitsplanactive to prsadmins with grant option
go
grant select on vw_arbeitsplanactive to prsusers
go

